home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr28 / du_1990.zip / DU.PAS < prev    next >
Pascal/Delphi Source File  |  1990-02-18  |  2KB  |  60 lines

  1. program DU;
  2. uses Dos;
  3.  
  4. type str80 = string[80];
  5.  
  6. procedure Instructions;
  7. begin
  8.   writeln('DU -- Disk usage report -- M. Covington 1990');
  9.   writeln;
  10.   writeln('du \');
  11.   writeln('    reports space used by all directories on disk');
  12.   writeln('du \mydir');
  13.   writeln('    reports space used by mydir and its subdirectories');
  14. end;
  15.  
  16. function SearchDirectory(Path,FileSpec:str80):longint;
  17.   { Searches the directory denoted by Path for files that match  }
  18.   { FileSpec, then does the same for all subdirectories under it }
  19. var  FileInfo: SearchRec;
  20.      Space: longint;
  21. begin
  22.      Space := 0;
  23.   { Look for files that match FileSpec }
  24.      FindFirst(Path+FileSpec,0,FileInfo);
  25.      while DOSerror = 0 do
  26.        begin
  27.          Space := Space + FileInfo.Size;
  28. {         writeln(Path+FileInfo.Name); }
  29.          FindNext(FileInfo)
  30.        end;
  31.   { Look for subdirectories and search them }
  32.      FindFirst(Path+'*.*',Directory,FileInfo);
  33.      while DOSerror = 0 do
  34.        begin
  35.          if ((FileInfo.Attr and Directory) > 0) and
  36.              (FileInfo.Name <> '.') and
  37.              (FileInfo.Name <> '..') then
  38.    Space := Space + SearchDirectory(Path+FileInfo.Name+'\',FileSpec);
  39.          FindNext(FileInfo)
  40.        end;
  41.   { Display and return the total space }
  42.     writeln(Space:25,'  ',Path);
  43.     SearchDirectory := Space
  44. end;
  45.  
  46. { Main program }
  47. var
  48.   Dir: Str80;
  49.   discard: longint;
  50. begin
  51.   if ParamCount = 0 then
  52.     Instructions
  53.   else
  54.     begin
  55.       Dir := ParamStr(1);
  56.       if Dir[length(Dir)] <> '\' then Dir := Dir + '\';
  57.       discard := SearchDirectory(Dir,'*.*')
  58.     end
  59. end.
  60.